package com.kaibo.roomdemo

import com.kaibo.roomdemo.net.api.TestApi
import com.kaibo.roomdemo.net.http.HttpClientUtil
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun test1() {
        val newScheduledThreadPool = Executors.newScheduledThreadPool(1)

        newScheduledThreadPool.scheduleWithFixedDelay({
            Thread.sleep(2000)
            println(1)
        }, 0, 1000, TimeUnit.MILLISECONDS)

        while (true);
    }

    @Test
    fun test2() {
        val myPrint: (String) -> Unit = ::println

        myPrint.invoke(factor(48))
    }

    private fun factor(n: Int): String {

        (2 until n).forEach {
            val x = n / it
            if (x * it == n) return "${factor(x)} x $it"
        }

        return "$n"
    }


    @Test
    fun test3() {
        val testClass = TestClass()

        val kFunction0 = TestClass::test111

        kFunction0.invoke(testClass, "12312")


    }

    class TestClass {
        fun test111(`in`: String) {
            println("测试方法-111 $`in`")
        }
    }

    @Test
    fun test4() {
        val arrayOf = arrayOf(true, false, true, true, false)
        val join = arrayOf.join('-')
        println(join)
    }

    @Test
    fun test5() {
        println(Thread.currentThread().name)
        HttpClientUtil
                .retrofit
                .create(TestApi::class.java)
                .getBaiduStr()
                .subscribe {
                    println(it.string())
                    println(Thread.currentThread().name)
                }

        while (true){

        }
    }

}
